<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/23 0023
 * Time: 9:17
 */
//include 'config.php';

header("content-Type:application/json;charset=utf-8");
header("Access-Control-Allow-Origin:*");
if ($_SERVER["REQUEST_METHOD"] == "POST"){
    if (isset($_POST["uname"])&&isset($_POST["upwd"])){
        $localhost="127.0.0.1";
        $dbname="root";
        $dbpwd="Chenzhou725925";
        $dbPort="3306";
        $database="maikaolin";

//1.创建链接对象
        $conn=new mysqli($localhost,$dbname,$dbpwd,$database,$dbPort);
//2. 设置链接字符集
        mysqli_query($conn,"set names utf8");
        $UNAME = $_POST["uname"];
        $UPWD = $_POST["upwd"];
        $sql="  SELECT `uid`,`uname` FROM userinfo WHERE uName='".$UNAME."' AND upwd='".$UPWD."'";
        $reuslt = $conn->query($sql);
        $arr = array("msg" => "登录失败", "status" => -1, "data" => "");
        if ($reuslt->num_rows >= 1) {
            $arr["msg"] = "登录成功";
            $arr["status"] = "1";
            $arr["data"] = $reuslt->fetch_assoc();
        }
        print_r(json_encode($arr));
        $conn->close();
    }else{
        print_r(json_encode(array("status"=>-2,"msg"=>"数据不合法")));
    }

}else{
    $arr = array("meg"=>"不支持GET请求","status"=>"-1");
    print_r(json_encode($arr));
}